#!/usr/bin/env python
import unittest
from core.player import Player

class PlayerTest(unittest.TestCase):
    def setUp(self):
        self.player = Player('xi.kun')
        
    def testPlayerHas4LifePointByDefault(self):
        self.assertEquals(4, self.player.get_life_points_left())
        self.assertEquals(4, self.player.get_starting_life_points())
        self.assertEquals(False, self.player.is_eliminated())
        self.assertEquals('xi.kun', self.player.get_name())
        
    def testPlayerLosesLifePoint(self):
        self.player.loses_life_point()
        self.assertEquals(3, self.player.get_life_points_left())
        self.assertEquals(4, self.player.get_starting_life_points())
        self.assertEquals(False, self.player.is_eliminated())
    
    def testPlayerIsEliminatedIfPlayerLosesHisLastLifePoint(self):
        self.player.loses_life_point()
        self.player.loses_life_point()
        self.player.loses_life_point()
        self.assertEquals(1, self.player.get_life_points_left())
        self.assertEquals(4, self.player.get_starting_life_points())
        self.assertEquals(False, self.player.is_eliminated())
        self.player.loses_life_point()
        self.assertEquals(0, self.player.get_life_points_left())
        self.assertEquals(4, self.player.get_starting_life_points())
        self.assertEquals(True, self.player.is_eliminated())
    
    def testShouldNotBeAffectdIfPlayerIsEliminated(self):
        self.player.loses_life_point()
        self.player.loses_life_point()
        self.player.loses_life_point()
        self.player.loses_life_point()
        self.assertEquals(0, self.player.get_life_points_left())
        self.assertEquals(4, self.player.get_starting_life_points())
        self.assertEquals(True, self.player.is_eliminated())
        self.player.loses_life_point()
        self.assertEquals(0, self.player.get_life_points_left())
        self.assertEquals(4, self.player.get_starting_life_points())
        self.assertEquals(True, self.player.is_eliminated())
     
if __name__ == '__main__':
    unittest.main()